var map = "";
var header_map = "";
var markers = [];
var labels_data = [];
var attr_map_popup = "";
var def_attr_id_show = [];
var surround_index = "";
var surround_timer = "";
var surround_timer_out = "";
var traf_wrap = $("#J_traf_wrap"), traf_fixed = $("#J_traffic_map_fix"), sur_wrap = $("#J_suround_wrap"), sur_fixed = $("#J_suround_wrap_m");
var attraction_index = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99];

if($("#J_map").length > 0){
var map = new AMap.Map('J_map', {
    zoom: 13,
    center: [config.hotel.lng, config.hotel.lat],
}, function () {
});

var googleLayer = new AMap.TileLayer({
    // 图块取图地址
    tileUrl: HQ.config.map.tileUrl,
    zIndex:100
});
googleLayer.setMap(map);

AMapUI.loadUI(['control/BasicControl'], function (BasicControl) {
    var zoomCtrl = new BasicControl.Zoom({
        position: 'RB',
    });
    map.addControl(zoomCtrl);
});
AMapUI.loadUI(['control/BasicControl'], function (BasicControl) {
    var zoomCtrl = new BasicControl.Zoom({
        position: 'RB',
    });
    attr_map_popup.addControl(zoomCtrl);
});

var hotel_marker = new AMap.Marker({
    map: map,
    position: [config.hotel.lng, config.hotel.lat],
    icon: new AMap.Icon({
        size: new AMap.Size(17, 26),  //图标大小
        image: "https://img.haoqiao.com/website/images/detail_map_traffic_icon.png",
        imageOffset: new AMap.Pixel(-16, -8),
    }),
});

hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
    offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
    content: '<div class="map-hotel-poi J_map_hotel_tips map-attr-detail-sur"><i class="list-icon-map"></i><div class="map-label-txt-w" style="top:-88px;left:-160px;"><div style="position:relative;z-index:20;width:350px; border:solid 2px #d88374;"><p class="map-label-txt text_show_ellipsis">'+ $("#J_hotel_tips_cont").attr("data-name") +'</p><p style="background: #fff;padding: 4px 6px;height: 35px;line-height:19px; width: auto;word-break: break-all;text-overflow: ellipsis;white-space: initial;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">'+ $("#J_hotel_tips_cont").attr("data-address") +'</p></div><span style="height:77px;" class="map-label-bg"></span></div></div>'
});



$("#J_traffic_jd").find("li").each(function(){
    var index = $("#J_traffic_jd").find("li").index(this) + 1;
    var id = $(this).attr("data-id");
    var latlng = $(this).attr("data-latlng").split(",");
    var cn_name = $(this).attr("data-name");
    var traffic = $(this).find("p").eq(1).html();


    var hotel_marker = new AMap.Marker({
        map: map,
        position: [latlng[1], latlng[0]],
        icon: new AMap.Icon({
            size: new AMap.Size(23, 32),  //图标大小
            image: "",
            imageOffset: new AMap.Pixel(-15, -135),
        }),
    });

    hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
        offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
        content: '<div class="map-attraction-poi-p J_map_icon_p map-attr-detail-sur J_icon'+ id +'"><i class="list-icon-map">'+ index +'</i><div class="map-label-txt-w" style="top:-88px;left:-60px;"><div style="position:relative;z-index:20;width:150px;border:solid 2px #d88374;"><p class="map-label-txt text_show_ellipsis">'+ cn_name +'</p><p class="text_break_word">'+ traffic +'</p></div><span style="height:77px;" class="map-label-bg"></span></div></div>'
    });


    var attr_t = setTimeout(function(){
        var attr_w = $(".J_icon"+ id).find(".map-label-txt-w");
        attr_w.css({left : -attr_w.width()/2 + 18});
    }, 100);



    $('#J_traffic_'+ id).mouseenter(function(){
        $(".J_icon"+ $(this).attr("data-id")).addClass("map-attraction-poi-p-hover").parent().css({zIndex : 10});
        $(".J_icon"+ $(this).attr("data-id")).parent().parent().css({zIndex : 110});
    }).mouseleave(function(){
        $(".J_icon"+ $(this).attr("data-id")).removeClass("map-attraction-poi-p-hover").parent().css({zIndex : 1});
        $(".J_map_icon_p").parent().parent().css({zIndex : 100});
    });
});

var traffic_timer = "";
var walking = "";
var WalkingRender = "";
WalkingRender = new Lib.AMap.WalkingRender();
$(".J_traffic_i").live("mouseenter", function(){
    _this = $(this);

    traffic_timer = setTimeout(function(){
        var latlng_place = _this.attr("data-latlng").split(",");

        walking = new AMap.Walking();

        walking.search(new AMap.LngLat(config.hotel.lng, config.hotel.lat), new AMap.LngLat(latlng_place[1],latlng_place[0]), function(status, result){
            if(status === 'complete'){
                WalkingRender.autoRender({
                    data: result,
                    map: map,
                });
            }
        });

    }, 500);
});
$(".J_traffic_i").live("mouseleave", function(){
    clearTimeout(traffic_timer);
    WalkingRender.clear();
});

function get_attraction_list(attr_id){
    def_attr_id_show = [];
    $("#J_traffic_jd").html("");
    HQ.ajax("/ajax/get_attraction_list?hotel_id="+ config.hotel.id +"&city_id="+ config.city +"&id="+ attr_id, {}, function(res){
        var _i = 0;
        for(var i in res) {
            if(typeof res[i][0] == "undefined"){
                continue;
            }
            $("#J_traffic_jd").append("<a href='/hotelmaps?city="+ config.city +"&landmark="+ res[i][0].id +"' target='_blank'><li id='J_traffic_"+ res[i][0].id +"' data-id='"+ res[i][0].id +"' data-latlng='"+ res[i][0].latitude +","+ res[i][0].longitude +"' class='detail-zb-title J_traffic_i' style='cursor:pointer'><i>"+ attraction_index[_i] +"</i><p class='detail-zb-cont-p'><span>"+ res[i][0].cn_name +"</span><em>"+ res[i][0].en_name +"</em></p><p>"+ res[i][0].traffic.replace(/，或.*$/, "") +"</li></a>");

            var hotel_marker = new AMap.Marker({
                map: map,
                position: [res[i][0].longitude, res[i][0].latitude],
                icon: new AMap.Icon({
                    size: new AMap.Size(23, 32),  //图标大小
                    image: "",
                    imageOffset: new AMap.Pixel(-15, -135),
                }),
            });

            hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
                offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
                content: '<div class="map-attraction-poi-p J_map_icon_p map-attr-detail-sur J_icon'+ res[i][0].id +'"><i class="list-icon-map">'+ attraction_index[_i] +'</i><div class="map-label-txt-w" style="top:-88px;left:-60px;"><div style="position:relative;z-index:20;width:150px;border:solid 2px #d88374;"><p class="map-label-txt text_show_ellipsis">'+ res[i][0].cn_name+'</p><p class="text_break_word">'+ res[i][0].traffic.replace(/，或.*$/, "") +'</p></div><span style="height:77px;" class="map-label-bg"></span></div></div>'
            });

            chked_attr(res[i][0].id);
            def_attr_id_show.push(res[i][0].id);
            def_attr_id_show = removeDuplicatedItem(def_attr_id_show);

            labels_data.push([[res[i][0].cn_name, res[i][0].latitude, res[i][0].longitude], '<div class="map-attraction-poi-p J_map_icon_p map-attr-detail-sur J_icon_popup'+ res[i][0].id +'"><i class="list-icon-map">'+ attraction_index[_i] +'</i><div class="map-label-txt-w"><p class="map-label-txt">'+ res[i][0].cn_name +'</p><span class="map-label-bg"></span></div></div>']);

            (function(i){
                $('#J_traffic_'+ res[i][0].id).mouseenter(function(){
                    $(".J_icon"+ $(this).attr("data-id")).addClass("map-attraction-poi-p-hover").parent().css({zIndex : 10});
                    $(".J_icon"+ $(this).attr("data-id")).parent().parent().css({zIndex:110});
                }).mouseleave(function(){
                    $(".J_icon"+ $(this).attr("data-id")).removeClass("map-attraction-poi-p-hover").parent().css({zIndex : 1});
                    $(".J_map_icon_p").parent().parent().css({zIndex:100});
                });
            })(i);

            _i++;
        }
    });
}

}

if($("#J_p_attr_map").length > 0){
var attr_map_popup = new AMap.Map('J_p_attr_map', {
    center: [config.hotel.lng, config.hotel.lat],
    zoom: 10
}, function () {
});

var googleLayer = new AMap.TileLayer({
    // 图块取图地址
    tileUrl: HQ.config.map.tileUrl,
    zIndex:100
});
googleLayer.setMap(attr_map_popup);



//更改景点
attraction_mange();


$(".J_map_icon").live("mouseenter", function(){
    $(this).addClass("map-attraction-poi-hover").parent().css({zIndex : 10});
});
$(".J_map_icon").live("mouseleave", function(){
    $(this).removeClass("map-attraction-poi-hover").parent().css({zIndex : 1});
});
$(".J_map_icon_p").live("mouseenter", function(){
    $(this).addClass("map-attraction-poi-p-hover").parent().css({zIndex : 10});
    $(this).parents('.amap-marker').css({zIndex : 150});
});
$(".J_map_icon_p").live("mouseleave", function(){
    $(this).removeClass("map-attraction-poi-p-hover").parent().css({zIndex : 1});
    $(this).parents('.amap-marker').css({zIndex : 100});
});
$(".J_map_icon1").live("mouseenter", function(){
    $(this).addClass("map-attraction-poi-p-hover").parent().css({zIndex : 10});
});
$(".J_map_icon1").live("mouseleave", function(){
    $(this).removeClass("map-attraction-poi-p-hover").parent().css({zIndex : 1});
});

$(".J_map_hotel_tips").live("mouseenter", function(){
    $(this).addClass("map-hotel-poi-hover").parent().css("z-index", 10);
    $(this).parents('.amap-marker').css({zIndex : 150});
});
$(".J_map_hotel_tips").live("mouseleave", function(){
    $(this).removeClass("map-hotel-poi-hover").parent().css("z-index", 1);
    $(this).parents('.amap-marker').css({zIndex : 100});
});
$(".J_hotel_map_t").live("mouseenter", function(){
    var index = $(".J_hotel_map_t").index(this);
    $(".J_map_hotel_tips").eq(index).addClass("map-hotel-poi-hover").parent().css("z-index", 10);
    $(".J_map_hotel_tips").eq(index).parents('.amap-marker').css({zIndex : 150});
});
$(".J_hotel_map_t").live("mouseleave", function(){
    var index = $(".J_hotel_map_t").index(this);
    $(".J_map_hotel_tips").eq(index).removeClass("map-hotel-poi-hover").parent().css("z-index", 1);
    $(".J_map_hotel_tips").eq(index).parents('.amap-marker').css({zIndex : 100});
});

/**
 * 景点管理功能
 */
function attraction_mange(){

    //更改景点
    $("#J_change_attraction").click(function(){

        var width = $(window).width() - 140;
        var height = $(window).height() - 80;
        var _this = $(this);

        $("#J_popup_attr").css({width : width, height : height});
        $("#J_p_attr_map").css({height : height});
        $("#J_p_attr_list").css({height : height - 30});
        var poition = HQ.util.position.centerPosition($("#J_popup_attr"));
        $("#J_popup_attr").css({left : poition.left, top : poition.top});
        $("#J_popup_attr").fadeIn("slow");

        HQ.util.show_bg();

        if(attr_map_popup != ""){



            var attr_t = setTimeout(function(){
                $(".J_map_icon_p").each(function(){
                    var attr_w = $(this).find(".map-label-txt-w");
                    attr_w.css({left : -attr_w.width()/2 + 18});
                });
            }, 100);



            HQ.ajax("/ajax/get_attraction_city?city_id="+ config.city, "", function(res){
                var data = {attr : [], shoping : [], traffic : [], other : []};
                var i = 0;
                var is_hot_traffic = 0;
                var is_hot_shoping = 0;
                for(var key in res){
                    if(res[key].category == 1 && (res[key].is_show == 1 || res[key].is_show == 2)){
                        data.attr.push(res[key]);
                    }else if(res[key].category == 2){
                        data.shoping.push(res[key]);
                        if(res[key].is_show == 1 || res[key].is_show == 2){
                            is_hot_shoping = 1;
                        }
                    }else if(res[key].category == 3){
                        data.traffic.push(res[key]);
                        if(res[key].is_show == 1 || res[key].is_show == 2){
                            is_hot_traffic = 1;
                        }
                    }else{
                        data.other.push(res[key]);
                    }
                    if(i > 97){
                        break;
                    }
                    i++;
                }

                var k = 1;
                var html = "";
                var attr_map_ch = {attr : HQ.config.language.attr_map_ch[language][0], shoping : HQ.config.language.attr_map_ch[language][1], traffic : HQ.config.language.attr_map_ch[language][2], other : HQ.config.language.attr_map_ch[language][3]};
                var sel_num = 0;
                var sel_num_html = "";
                for(var key in data){
                    if(data[key].length != 0){
                        html += "<dl><dt><span>"+ attr_map_ch[key] +"</span></dt>";
                        var more_num = 0;
                        for(var i = 0; i < data[key].length; i++){
                            var _hide = "";
                            var chkd = "";
                            var name = "";
                            var name_h = "";
                            var is_sel = 0;
                            if(key == "other" && i >= 4){
                                _hide = "J_attr_item";
                                more_num++;
                            }

                            if(key == "shoping" && is_hot_shoping == 0){
                                if(i > 4){
                                    _hide = "J_attr_item";
                                    more_num++;
                                }
                            }else if(key == "shoping" && is_hot_shoping == 1 && (data[key][i].is_show == 3 || data[key][i].is_show == 0)){
                                _hide = "J_attr_item";
                                more_num++;
                            }

                            if(key == "traffic" && is_hot_traffic == 0){
                                if(i > 4){
                                    _hide = "J_attr_item";
                                    more_num++;
                                }
                            }else if(key == "traffic" && is_hot_traffic == 1 && (data[key][i].is_show == 3 || data[key][i].is_show == 0)){
                                _hide = "J_attr_item";
                                more_num++;
                            }


                            if(def_attr_id_show.in_array(data[key][i].id +"") !== false || def_attr_id_show.in_array(data[key][i].id) !== false){
                                chkd = "current";
                                is_sel = 1;
                                sel_num++;
                            }
                            if(data[key][i].cn_name == ""){
                                name = data[key][i].name;
                                name_h = data[key][i].name;
                            }else{
                                name = data[key][i].cn_name;
                                name_h = data[key][i].cn_name +"<span>"+ data[key][i].name +"</span>";
                            }

                            html += '<dd class="J_attr_chk '+ chkd +' '+ _hide +'" data-issel="'+ is_sel +'" data-name="'+ name +'" data-id="'+ data[key][i].id +'" data-latlng="'+ data[key][i].latitude +','+ data[key][i].longitude +'" data-sort-id="'+ k +'"><i></i>  '+ k +'. '+ name_h +'</dd>';

                            if(is_sel == 1){
                                var hotel_marker = new AMap.Marker({
                                    map: attr_map_popup,
                                    position: [data[key][i].longitude, data[key][i].latitude],
                                    icon: new AMap.Icon({
                                        size: new AMap.Size(23, 32),  //图标大小
                                        image: "",
                                        imageOffset: new AMap.Pixel(-15, -135),
                                    }),
                                });

                                hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
                                    offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
                                    content: '<div class="map-attraction-poi-p J_map_icon_p map-attr-detail-sur J_icon_popup'+ data[key][i].id +'"><i class="list-icon-map">'+ k +'</i><div class="map-label-txt-w"><p class="map-label-txt">'+ name_h +'</p><span class="map-label-bg"></span></div></div>'
                                });

                            }

                            k++;

                        }
                        if(more_num > 0){
                            html += "<a href='javascript:' data-tips='"+HQ.config.language.common[language][0]+ more_num +HQ.config.language.common[language][1]+ attr_map_ch[key] +"' class='J_more_attr_p' data-show='0'>"+HQ.config.language.common[language][0]+ more_num +HQ.config.language.common[language][1]+ attr_map_ch[key] +"</a>";
                        }

                        if(sel_num > 0){
                            sel_num_html = HQ.config.language.common[language][2]+" <i>"+ sel_num +"</i> "+HQ.config.language.common[language][1]+"，"+HQ.config.language.common[language][3];
                        }

                        html += "</dl>";


                    }
                }

                $("#J_attr_num").html(sel_num_html);
                $("#J_p_attr_list").html(html);

                if(sel_num >= 15){
                    $(".J_attr_chk").each(function(){
                        if($(this).attr("data-issel") == 0){
                            $(this).addClass("unchk");
                        }
                    });
                }

                //添加展开景点
                $(".J_more_attr_p").click(function(){
                    var is_show = $(this).attr("data-show");

                    if(is_show == 1){
                        $(this).attr("data-show", 0).html($(this).attr("data-tips")).parent().find(".J_attr_item").hide();
                    }else{
                        $(this).attr("data-show", 1).html(HQ.config.language.common[language][4]).parent().find(".J_attr_item").show();
                    }
                });
                //添加选中点击
                $(".J_attr_chk").click(function(){

                    var is_sel = $(this).attr("data-issel");

                    if(is_sel == 0){
                        if(sel_num >= 15){
                            $(this).append("<div class='J_chk_more_tips' style='position:absolute;top:2px;left:22px;padding:3px 5px;background:#ffffa3;color:#666'>"+HQ.config.language.common[language][3]+"</div>");
                            var timer_tips = setTimeout(function(){
                                $(".J_chk_more_tips").fadeOut(function(){
                                    $(this).remove();
                                });
                            }, 800);
                            return false;
                        }
                        sel_num++;
                        $("#J_attr_num").html(HQ.config.language.common[language][2]+" <i>"+ sel_num +"</i> "+HQ.config.language.common[language][1]+"，"+HQ.config.language.common[language][3]);
                        $(this).addClass("current").attr("data-issel", 1);

                        $(".J_attr_chk").each(function(key,value){
                            if($(this).attr("data-issel") == 1){
                                var latlng = $(this).attr("data-latlng").split(",");
                                var index = key + 1;
                                var id = $(this).attr("data-id");
                                var cn_name = $(this).attr("data-name");
                                var sort_id = $(this).attr("data-sort-id");

                                var hotel_marker = new AMap.Marker({
                                    map: attr_map_popup,
                                    position: [latlng[1], latlng[0]],
                                    icon: new AMap.Icon({
                                        size: new AMap.Size(23, 32),  //图标大小
                                        image: "",
                                        imageOffset: new AMap.Pixel(-15, -135),
                                    }),
                                });

                                hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
                                    offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
                                    content: '<div class="map-attraction-poi-p J_map_icon_p map-attr-detail-sur J_icon_popup'+ id +'"><i class="list-icon-map">'+ sort_id +'</i><div class="map-label-txt-w"><p class="map-label-txt">'+ cn_name +'</p><span class="map-label-bg"></span></div></div>'
                                });

                            }
                        });

                        if(sel_num == 15){
                            $(".J_attr_chk").each(function(){
                                if($(this).attr("data-issel") == 0){
                                    $(this).addClass("unchk");
                                }
                            });
                        }


                    }else{
                        sel_num--;
                        sel_num == 0 ? $("#J_attr_num").html("") : $("#J_attr_num").html(HQ.config.language.common[language][2]+" <i>"+ sel_num +"</i> "+HQ.config.language.common[language][1]+"，"+HQ.config.language.common[language][3]);
                        $(this).removeClass("current").attr("data-issel", 0);
                        $(".J_attr_chk").removeClass("unchk");
                    }


                }).mouseenter(function(){
                    if (!$(this).is(":animated")) {
                        var is_sel = $(this).attr("data-issel");
                        var id = $(this).attr("data-id");
                        var index = $(".J_attr_chk").index(this);
                        var sort_id = $(this).attr("data-sort-id");

                        if (is_sel == 0) {
                            var latlng = $(this).attr("data-latlng").split(",");
                            var hotel_marker = new AMap.Marker({
                                map: attr_map_popup,
                                position: [latlng[1], latlng[0]],
                                icon: new AMap.Icon({
                                    size: new AMap.Size(23, 32),  //图标大小
                                    image: "",
                                    imageOffset: new AMap.Pixel(-15, -135),
                                }),
                            });

                            hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
                                offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
                                content: '<div class="map-attraction-poi-p J_map_icon_p map-attr-detail-sur J_icon_popup' + $(this).attr("data-id") + ' map-attraction-poi-p-hover"><i class="list-icon-map">' + sort_id + '</i><div class="map-label-txt-w"><p class="map-label-txt">' + $(this).attr("data-name") + '</p><span class="map-label-bg"></span></div></div>'
                            });

                        } else {
                            $(".J_icon_popup" + $(this).attr("data-id")).addClass("map-attraction-poi-p-hover").parent().css({zIndex: 10});
                            $(".J_icon_popup" + $(this).attr("data-id")).parent().parent().css({zIndex:110});
                        }
                    }
                }).mouseleave(function(){
                    var is_sel = $(this).attr("data-issel");
                    $(".J_map_icon_p").removeClass("map-attraction-poi-p-hover").parent().css({zIndex: 1});
                    $(".J_map_icon_p").parent().parent().css({zIndex:100});

                    if (is_sel == 0) {
                        $(".J_icon_popup" + $(this).attr("data-id")).parent().remove();
                    }
                });

            });
        }
        $("body").css({overflow : "hidden"});

        return false;
    });
}

//景点选择
$("#J_attr_sub").click(function(){

    $(".J_map_icon").parent().remove();
    $(".J_map_icon_p").parent().remove();
    $("#J_traffic_jd").html("");
    var i = 0;
    var attr_cookie = "";
    def_attr = $(".J_attraction span").length;


    $(".J_attr_chk").each(function(){
        if($(this).attr("data-issel") == 1){
            var id = $(this).attr("data-id");
            var latlng = $(this).attr("data-latlng").split(",");
            var index = $(".J_attr_chk").index(this);
            var sort_id = $(this).attr("data-sort-id");

            var hotel_marker = new AMap.Marker({
                map: attr_map_popup,
                position: [latlng[1], latlng[0]],
                icon: new AMap.Icon({
                    size: new AMap.Size(23, 32),  //图标大小
                    image: "",
                    imageOffset: new AMap.Pixel(-15, -135),
                }),
            });

            hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
                offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
                content: '<div class="map-attraction-poi-p J_map_icon_p map-attr-detail-sur J_icon_popup'+ id +'"><i class="list-icon-map">'+ sort_id +'</i><div class="map-label-txt-w"><p class="map-label-txt">'+ $(this).attr("data-name") +'</p><span class="map-label-bg"></span></div></div>'
            });


            attr_cookie += id+",";


            (function(i){
                $('#J_traffic_'+ id).mouseenter(function(){
                    $(".J_icon"+ $(this).attr("data-id")).addClass("map-attraction-poi-p-hover").parent().css({zIndex : 10});
                    $(".J_icon"+ $(this).attr("data-id")).parent().parent().css({zIndex : 100});
                }).mouseleave(function(){
                    $(".J_icon"+ $(this).attr("data-id")).removeClass("map-attraction-poi-p-hover").parent().css({zIndex : 1});
                    $(".J_map_icon_p").parent().parent().css({zIndex : 100});
                });
            })(i);
            i++;
        }
    });

    traf_fixed.css({position : "relative", top : 0});



    HQ.set_cookie("attraction_id", "");
    HQ.set_cookie("attraction_id", config.city +"|"+ attr_cookie);
    $("#J_popup_attr").fadeOut("slow");
    $("#bg").fadeOut("slow");

    $("body").css({overflow : "auto"});

    //get_traffic(attr_cookie);

    get_attraction_list(attr_cookie);

    return false;
});

//初始化景点
get_def_attraction();

//初始化景点
function get_def_attraction(){
    $("#J_traffic_jd").find("li").each(function(){
        var index = $("#J_traffic_jd").find("li").index(this) + 1;
        var id = $(this).attr("data-id");
        var latlng = $(this).attr("data-latlng").split(",");
        var cn_name = $(this).attr("data-name");



        var attr_t = setTimeout(function(){
            var attr_w = $(".J_icon"+ id).find(".map-label-txt-w");
            attr_w.css({left : -attr_w.width()/2 + 18});
        }, 100);

        chked_attr(id);
        def_attr_id_show.push(id+"");


        $('#J_traffic_'+ id).mouseenter(function(){
            $(".J_icon"+ $(this).attr("data-id")).addClass("map-attraction-poi-p-hover").parent().css({zIndex : 10});
            $(".J_icon"+ $(this).attr("data-id")).parent().parent().css({zIndex : 110});
        }).mouseleave(function(){
            $(".J_icon"+ $(this).attr("data-id")).removeClass("map-attraction-poi-p-hover").parent().css({zIndex : 1});
            $(".J_map_icon_p").parent().parent().css({zIndex : 100});
        });
    });

}

function chked_attr(id){
    $(".J_chk_attr").each(function(){
        if($(this).val() == id){
            $(this).attr("checked", "checked");
            return false;
        }
    });
}

}
$("#J_close_attr").click(function(){
    $("#J_popup_attr").fadeOut("slow");
    $("#bg").fadeOut("slow");
    $("body").css({overflow : "auto"});
});

if($("#J_map_1").length > 0){
    var zb_map = new AMap.Map('J_map_1', {
        center: [config.hotel.lng, config.hotel.lat],
        zoom: 13
    }, function () {
    });

    var googleLayer = new AMap.TileLayer({
        // 图块取图地址
        tileUrl: HQ.config.map.tileUrl,
        zIndex:100
    });
    googleLayer.setMap(zb_map);

    AMapUI.loadUI(['control/BasicControl'], function (BasicControl) {
        var zoomCtrl = new BasicControl.Zoom({
            position: 'RB',
        });
        zb_map.addControl(zoomCtrl);
    });

    var zb_hotel_marker = new AMap.Marker({
        map: zb_map,
        position: [config.hotel.lng, config.hotel.lat],
        icon: new AMap.Icon({
            size: new AMap.Size(17, 26),  //图标大小
            image: "https://img.haoqiao.com/website/images/detail_map_traffic_icon.png",
            imageOffset: new AMap.Pixel(-16, -8),
        }),
    });


zb_hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
        offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
        content: '<div class="map-hotel-poi J_map_hotel_tips map-attr-detail-sur"><i class="list-icon-map"></i><div class="map-label-txt-w" style="top:-88px;left:-160px;"><div style="position:relative;z-index:20;width:350px;border:solid 2px #d88374;"><p class="map-label-txt text_show_ellipsis">'+ $("#J_hotel_tips_cont").attr("data-name") +'</p><p class="text_break_word">'+ $("#J_hotel_tips_cont").attr("data-address") +'</p></div><span style="height:77px;" class="map-label-bg"></span></div></div>'
    });

zb();

function zb(){
    $("#J_server li").click(function(){
        var is_fold = $(this).attr("data-fold");
        $("#J_server li").attr("data-fold", 0);
        if(is_fold == 0){
            var k = $("#J_server li").index(this);
            $(this).addClass("current").siblings().removeClass("current");

            $(".J_map_icon1").parent().remove();
            $(".J_server_list").eq(k).find(".J_detail_zb_list").each(function(){
                var index = $(".J_server_list").eq(k).find(".detail-zb-list").index(this);
                var latlng = $(this).attr("data-latlng").split(",");

                var hotel_marker = new AMap.Marker({
                    map: zb_map,
                    position: [latlng[1], latlng[0]],
                    icon: new AMap.Icon({
                        size: new AMap.Size(17, 26),  //图标大小
                        image: "",
                        imageOffset: new AMap.Pixel(-16, -8),
                    }),
                });


                hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
                    offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
                    content: '<div class="map-attraction-poi-p map-attr-detail-sur J_map_icon1"><i class="list-icon-map">'+ (index + 1) +'</i><div class="map-label-txt-w"><p class="map-label-txt">'+ $(this).attr("data-name") +'</p><span class="map-label-bg"></span></div></div>'
                });

                var attr_t = setTimeout(function(){
                    var attr_w = $(".J_map_icon1").eq(index).find(".map-label-txt-w");
                    attr_w.css({left : -attr_w.width()/2 + 18});
                }, 100);

            });


            $(".J_server_list").eq(k).find(".J_detail_zb_list").mouseenter(function(){
                var index = $(".J_server_list").eq(k).find(".J_detail_zb_list").index(this);
                $(".J_map_icon1").eq(index).addClass("map-attraction-poi-p-hover").parent().css({zIndex : 10});
                $(".J_map_icon1").eq(index).parent().parent().css({zIndex : 110});
            }).mouseleave(function(){
                var index = $(".J_server_list").eq(k).find(".J_detail_zb_list").index(this);
                $(".J_map_icon1").eq(index).removeClass("map-attraction-poi-p-hover").parent().css({zIndex : 1});
                $(".J_map_icon1").parent().parent().css({zIndex : 100});
            });

            surround_index = k;

            $(this).attr("data-fold", 1);
        }else{
            $(".J_map_icon1").parent().remove();
            $(this).removeClass("current");

            $(this).attr("data-fold", 0);

            $("#J_suround_wrap_m").css({position : "relative", top : 0});

            surround_index = "";
        }
    }).mouseenter(function(){
        var k = $("#J_server li").index(this);

        if(surround_index === k){
            return false;
        }
        surround_timer = setTimeout(function(){
            //var map_zb_bounds = new google.maps.LatLngBounds();
            //map_zb_bounds.extend(strat_latlng);

            $(".J_map_icon1").parent().remove();
            $(".J_server_list").eq(k).find(".J_detail_zb_list").each(function(){
                var index = $(".J_server_list").eq(k).find(".J_detail_zb_list").index(this);
                var latlng = $(this).attr("data-latlng").split(",");

                var hotel_marker = new AMap.Marker({
                    map: zb_map,
                    position: [latlng[1], latlng[0]],
                    icon: new AMap.Icon({
                        size: new AMap.Size(17, 26),  //图标大小
                        image: "",
                        imageOffset: new AMap.Pixel(-16, -8),
                    }),
                });
                hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
                    offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
                    content: '<div class="map-attraction-poi-p map-attr-detail-sur J_map_icon1"><i class="list-icon-map">'+ (index + 1) +'</i>' +
                    '<div class="map-label-txt-w"><p class="map-label-txt">'+ $(this).attr("data-name") +'</p><span class="map-label-bg"></span></div></div>'
                });

                var attr_t = setTimeout(function(){
                    var attr_w = $(".J_map_icon1").eq(index).find(".map-label-txt-w");
                    attr_w.css({left : -attr_w.width()/2 + 18});
                }, 100);

            });

        }, 300);

        clearTimeout(surround_timer_out);

    }).mouseleave(function(){
        var k = $("#J_server li").index(this);
        clearTimeout(surround_timer);

        surround_timer_out = setTimeout(function(){
            if(surround_index !== k && surround_index !== ""){
                $(".J_map_icon1").parent().remove();
                $(".J_server_list").eq(surround_index).find(".J_detail_zb_list").each(function(){
                    var index = $(".J_server_list").eq(surround_index).find(".detail-zb-list").index(this);
                    var latlng = $(this).attr("data-latlng").split(",");

                    var hotel_marker = new AMap.Marker({
                        map: zb_map,
                        position: [latlng[1], latlng[0]],
                        icon: new AMap.Icon({
                            size: new AMap.Size(17, 26),  //图标大小
                            image: "",
                            imageOffset: new AMap.Pixel(-16, -8),
                        }),
                    });
                    hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
                        offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
                        content: '<div class="map-attraction-poi-p map-attr-detail-sur J_map_icon1"><i class="list-icon-map">'+ (index + 1) +'</i><div class="map-label-txt-w"><p class="map-label-txt">'+ $(this).attr("data-name") +'</p><span class="map-label-bg"></span></div></div>'
                    });

                    var attr_t = setTimeout(function(){
                        var attr_w = $(".J_map_icon1").eq(index).find(".map-label-txt-w");
                        attr_w.css({left : -attr_w.width()/2 + 18});
                    }, 100);
                });
            }else if(surround_index !== k){
                $(".J_map_icon1").parent().remove();
            }
        }, 300);

    });

    $(".J_zb_list_title").mouseenter(function(){
        $(this).addClass("detail-server-title-zb-cur");
    }).mouseleave(function(){
        $(this).removeClass("detail-server-title-zb-cur");
    });


}
}

function removeDuplicatedItem(ar) {
    var ret = [];

    for (var i = 0, j = ar.length; i < j; i++) {
        if (ret.indexOf(ar[i]) === -1) {
            ret.push(ar[i]);
        }
    }

    return ret;
}

if($("#J_header_map").length > 0){
var header_map = new AMap.Map('J_header_map', {
	dragEnable: false,
	zoomEnable:false,
    zoom: 13,
    center: [config.hotel.lng, config.hotel.lat],
	showZoomBar:false
}, function () {
});

var googleLayer = new AMap.TileLayer({
    // 图块取图地址
    tileUrl: HQ.config.map.tileUrl,
    zIndex:100
});
googleLayer.setMap(header_map);

header_map.plugin(["AMap.ControlBar"],function(){
    var controlBar = new AMap.ControlBar({showZoomBar:false})
    header_map.addControl(controlBar)
});


header_map.panBy(20, 40);

var hotel_marker = new AMap.Marker({
    map: header_map,
    position: [config.hotel.lng, config.hotel.lat],
    icon: new AMap.Icon({
        size: new AMap.Size(17, 26),  //图标大小
        image: "https://img.haoqiao.com/website/images/hotel_detail/hotel_mark.png",
        imageOffset: new AMap.Pixel(-16, -8),
    }),
});

hotel_marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
    offset: new AMap.Pixel(8, 25),//修改label相对于maker的位置
    content: '<div class="map-header-hotel-poi J_map_header_hotel_tips map-header-attr-detail-sur map-header-hotel-poi-hover">' +
    '<i class="list-icon-map bg-hotel_mark"></i><a  onclick="hotelinfo_click(\''+HQ.config.language.attr_map_ch[language][5]+'\');">' +
    '<div class="map-label-txt-w" style="top: -13px;left: -30px;position: relative;"><div  class="map-header-hotel-poi-i">' +
    '<i class="arrow-up-map"></i><p class="map-label-txt"><span class="message-hoteldetail bg-hotel_mark_pop"></span></p></div></div></a></div>'
});

}




